package ru.amse.tsyganov.jumleditor.view.activepoints;

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

import ru.amse.tsyganov.jumleditor.graphicaleditor.Coordinates;
import ru.amse.tsyganov.jumleditor.view.preferences.Colors;

public abstract class ResizeActivePoint extends ActivePoint {
	
	public abstract int getNewWidth();
	
	public abstract int getNewHeight();
	
	public abstract Rectangle getTemporaryRectangle();

	@Override
	public final void paintTempResult(GC gc, Coordinates coordinates) {
		assert gc != null;
		
		gc.setAlpha(50);
		
		gc.setBackground(Colors.getBlackColor());
		gc.setForeground(Colors.getBlackColor());
		
		Rectangle r = getTemporaryRectangle();
		gc.fillRectangle(
				coordinates.fromModelXToScreenX(r.x),
				coordinates.fromModelYToScreenY(r.y),
				r.width, r.height);
		gc.drawRectangle(
				coordinates.fromModelXToScreenX(r.x),
				coordinates.fromModelYToScreenY(r.y),
				r.width, r.height);
		
		gc.setAlpha(255);
	}

	protected final boolean isNewResultsCorrect() {
		return !(getNewWidth() < 20 || getNewHeight() < 20);
	}

}
